package com.peanut.wapp.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.peanut.wapp.controller.res.PageResult;
import com.peanut.wapp.controller.resBean.RFeeBean;
import com.peanut.wapp.model.FeeBean;
import com.peanut.wapp.persist.FeeDao;
import com.peanut.wapp.service.FeeService;
import com.peanut.wapp.util.AppTextUtil;
import com.peanut.wapp.util.DateTimeUtil;

@Service
public class FeeServiceImpl implements FeeService {
				
	@Autowired
	FeeDao feeImpl;


	@Override
	public boolean commit(int type, int deliver, int confinement, int value_add, String phone, String host) {
		FeeBean fee = new FeeBean();
		fee.setFid(AppTextUtil.getPrimaryKey());
		fee.setConfinementCycle(confinement);
		fee.setType(type);
		fee.setDeliveryCycle(deliver);
		fee.setValueAdd(value_add);
		fee.setPhone(phone);
		fee.setHost(host);
		
		return feeImpl.insert(fee) > 0;
	}


	@Override
	public PageResult<RFeeBean> getList(String key, int start, int pageSize) {
		PageResult<RFeeBean> result = new PageResult<RFeeBean>();
		int count = feeImpl.selectCount(key);
		List<FeeBean> resList = feeImpl.selectList(key, start, pageSize);
		System.out.println(resList);
		List<RFeeBean> resData = new ArrayList<>();
		for(FeeBean co : resList) {
			RFeeBean rc = new RFeeBean();
			if(co.getCreateTime()!= null) {
				rc.setCreateTime(DateTimeUtil.formatTimestamp(co.getCreateTime().getTime()/1000, null));
			}
			rc.setConfinementCycle(co.getConfinementCycle());
			rc.setDeliveryCycle(co.getDeliveryCycle());
			rc.setFid(co.getFid());
			rc.setPhone(co.getPhone());
			rc.setType(co.getType());
			rc.setHost(co.getHost());
			rc.setStatus(co.getStatus());
			rc.setValueAdd(co.getValueAdd());
			resData.add(rc);
		}
		result.setCount(count);
		result.setData(resData);
		return result;
	}


}
